{include file='pub/header'/}
<title>基础统计</title>
</head>
<body>
<nav class="breadcrumb">{$breadNav} <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                                       href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <form action="" method="get">
        <div class="text-c"> 日期：
            <input type="text" value="{$param.mintime || default=''}" onfocus="WdatePicker({maxDate:'#F{ $dp.$D(\'datemax\')}'})" id="datemin" name="mintime"
                   class="input-text Wdate" autocomplete="off" style="width:120px;">
            -
            <input type="text" value="{$param.maxtime || default=''}" onfocus="WdatePicker({minDate:'#F{ $dp.$D(\'datemin\')}'})" id="datemax" name="maxtime"
                   class="input-text Wdate" autocomplete="off" style="width:120px;">
            <button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 查询
            </button>
            <button type="button" class="btn btn-success export-btn"><i class="Hui-iconfont Hui-iconfont-down"></i> 下载
            </button>

        </div>
    </form>
    <table class="table table-border table-bordered table-bg table-sort">
        <thead>
        <tr>
            <th scope="col" colspan="9">基础统计(<span style="color:red;">由于数据关联过多，查询/下载请控制在一个月以内</span>)</th>
        </tr>
        <tr class="text-c">
            <th>日期</th>
            <th>新增会员数量</th>
            <th>安卓启动次数</th>
            <th>苹果启动次数</th>
            <th>小程序启动次数</th>
            <th>产品分类访问数量</th>
            <th>产品详情访问数量</th>
            <th>产品搜索访问数量</th>
            <th>用户登录次数</th>
        </tr>
        </thead>
        <tbody>
        {foreach $list as $v}
        <tr class="text-c">
            <td>{$v.date}</td>
            <td>{$v.user_num}</td>
            <td>{$v.android}</td>
            <td>{$v.ios}</td>
            <td>{$v.wapp}</td>
            <td>{$v.cate_count}</td>
            <td>{$v.product_count}</td>
            <td>{$v.keys_count}</td>
            <td>{$v.login_count}</td>
        </tr>
        {/foreach}
        </tbody>
    </table>
</div>

<table id="data" style="display: none;">
    <thead>
    <tr>
        <th scope="col" colspan="9">基础统计</th>
    </tr>
    <tr class="text-c">
        <th>日期</th>
        <th>新增会员数量</th>
        <th>安卓启动次数</th>
        <th>苹果启动次数</th>
        <th>小程序启动次数</th>
        <th>产品分类访问数量</th>
        <th>产品详情访问数量</th>
        <th>产品搜索访问数量</th>
        <th>用户登录次数</th>
    </tr>
    </thead>
    <tbody>
    {foreach $list as $v}
    <tr class="text-c">
        <td>{$v.date}</td>
        <td>{$v.user_num}</td>
        <td>{$v.android}</td>
        <td>{$v.ios}</td>
        <td>{$v.wapp}</td>
        <td>{$v.cate_count}</td>
        <td>{$v.product_count}</td>
        <td>{$v.keys_count}</td>
        <td>{$v.login_count}</td>
    </tr>
    {/foreach}
    </tbody>
</table>
<a href="" style="display: none;" id="dlink"></a>
{include file="pub/footer"/}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    $('.table-sort').dataTable({
        "aaSorting": [[0, "desc"]],//默认第几个排序
        "bStateSave": true,//状态保存
    });
    $(function () {
        $(".export-btn").click(function () {
            method1(data, "基础统计", "基础统计.xls");
        });
    })

    var idTmr;

    function getExplorer() {
        var explorer = window.navigator.userAgent;
        //ie
        if (explorer.indexOf("MSIE") >= 0) {
            return 'ie';
        }
        //firefox
        else if (explorer.indexOf("Firefox") >= 0) {
            return 'Firefox';
        }
        //Chrome
        else if (explorer.indexOf("Chrome") >= 0) {
            return 'Chrome';
        }
        //Opera
        else if (explorer.indexOf("Opera") >= 0) {
            return 'Opera';
        }
        //Safari
        else if (explorer.indexOf("Safari") >= 0) {
            return 'Safari';
        }
    }

    function method1(tableid, name, filename) {
        //整个表格拷贝到EXCEL中
        if (getExplorer() == 'ie') {
            var curTbl = document.getElementById(tableid);
            var oXL = new ActiveXObject("Excel.Application");
            //创建AX对象excel
            var oWB = oXL.Workbooks.Add();
            //获取workbook对象
            var xlsheet = oWB.Worksheets(1);
            //激活当前sheet
            var sel = document.body.createTextRange();
            sel.moveToElementText(curTbl);
            //把表格中的内容移到TextRange中
            sel.select();
            //全选TextRange中内容
            sel.execCommand("Copy");
            //复制TextRange中内容
            xlsheet.Paste();
            //粘贴到活动的EXCEL中
            oXL.Visible = true;
            //设置excel可见属性

            try {
                var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
            } catch (e) {
                print("Nested catch caught " + e);
            } finally {
                oWB.SaveAs(fname);

                oWB.Close(savechanges = false);
                //xls.visible = false;
                oXL.Quit();
                oXL = null;
                //结束excel进程，退出完成
                //window.setInterval("Cleanup();",1);
                idTmr = window.setInterval("Cleanup();", 1);

            }

        }
        else {
            tableToExcel(tableid, name, filename);
        }

    }

    function Cleanup() {
        window.clearInterval(idTmr);
        CollectGarbage();
    }

    var tableToExcel = (function () {
        var uri = 'data:application/vnd.ms-excel;base64,',
            template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
            base64 = function (s) {
                return window.btoa(unescape(encodeURIComponent(s)))
            },
            format = function (s, c) {
                return s.replace(/{(\w+)}/g,
                    function (m, p) {
                        return c[p];
                    })
            }
        return function (table, name, filename) {
            if (!table.nodeType) table = document.getElementById(table)
            var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
            // window.location.href = uri + base64(format(template, ctx))
            let blob = new Blob([format(template, ctx)]);
            document.getElementById("dlink").href = URL.createObjectURL(blob);
            // document.getElementById("dlink").href = uri + base64(format(template, ctx));
            document.getElementById("dlink").download = filename;
            document.getElementById("dlink").click();
        }
    })();
</script>
</body>
</html>